(function(f, g, d) {
    var b = mobiscroll,
        a = b.$,
        e = a.extend,
        c = b.classes;
    c.MenuStrip = function(D, I) {
        var m, k, y, B, j, H, G, n, q, F, E, p, s, o, x, g, t, l, v = 1000,
            h = this,
            i = a(D);

        function z(a) {
            clearTimeout(E);
            E = setTimeout(function() {
                C(a.type !== 'load');
            }, 200);
        }

        function w(b, c) {
            if (!b.length) {
                return;
            }
            var g = b.offset().left,
                e = b[0].offsetLeft,
                f = b[0].offsetWidth,
                h = k.offset().left;
            m = b;
            if (c === d) {
                c = !q;
            }
            if (p && c) {
                if (q) {
                    if (b.attr('data-selected')) {
                        u(b);
                    } else {
                        A(b);
                    }
                } else {
                    u(a('.mbsc-ms-item-sel', i));
                    A(b);
                }
            }
            if (x == 'a') {
                if (g < h) {
                    o.scroll(-e, v, true);
                } else if (g + f > h + j) {
                    o.scroll(j - e - f, v, true);
                }
            } else {
                o.scroll(j / 2 - e - f / 2, v, true);
            }
            if (c) {
                l('onItemTap', {
                    target: b[0]
                });
            }
        }

        function A(a) {
            a.addClass(s).attr('data-selected', 'true').attr('aria-selected', 'true');
        }

        function u(a) {
            a.removeClass(s).removeAttr('data-selected').removeAttr('aria-selected');
        }

        function r(b) {
            if (typeof b !== 'object') {
                b = i.children('[data-id="' + b + '"]');

            }
            return a(b);
        }

        function J() {
            l('onMarkupInit');
            i.children().each(function(j) {
                var f, c, b = a(this),
                    d = p && b.attr('data-selected') == 'true',
                    i = b.attr('data-disabled') == 'true',
                    e = b.attr('data-icon');
                if (j === 0) {
                    y = b;
                }
                if (p && !q && d) {
                    m = b;
                }
                if (b.children().length !== 1) {
                    a('<span></span>').append(b.contents()).appendTo(b);
                }
                c = b.children().eq(0);
                if (e) {
                    H = true;
                }
                if (c.hasClass('mbsc-ms-item-i')) {
                    return;
                }
                if (c.html()) {
                    G = true;
                }
                f = a('<span class="mbsc-ms-item-i-t"><span class="mbsc-ms-item-i-c"></span></span>');
                f.find('.mbsc-ms-item-i-c').append(c.contents());
                c.addClass('mbsc-ms-item-i' + (e ? ' mbsc-ms-ic mbsc-ic mbsc-ic-' + e : '')).append(f);
                b.attr('data-role', 'button').attr('aria-selected', d ? 'true' : null).attr('aria-disabled', i ? 'true' : null).addClass('mbsc-ms-item mbsc-btn-e ' + (g.itemClass || '') + (d ? s : '') + (i ? ' mbsc-btn-d ' + (g.disabledClass || '') : ''));
            });
            if (H) {
                k.addClass('mbsc-ms-icons');
            }
            if (G) {
                k.addClass('mbsc-ms-txt');
            }
        }

        function C(d, f) {
            var a = g.itemWidth,
                c = g.layout;
            h.contWidth = j = k.width();
            if (d && F === j || !j) {
                return;
            }
            F = j;
            if (b.util.isNumeric(c)) {
                n = j ? j / c : a;
                if (n < a) {
                    c = 'liquid';
                }
            }
            if (a) {
                if (c == 'liquid') {
                    n = j ? j / Math.min(Math.floor(j / a), i.children().length) : a;
                } else if (c == 'fixed') {
                    n = a;
                }
            }
            if (n) {
                i.children().css('width', n + 'px');
            }
            i.contents().filter(function() {
                return this.nodeType == 3 && !/\S/.test(this.nodeValue);
            }).remove();
            h.totalWidth = t = i.width();
            e(o.settings, {
                contSize: j,
                maxSnapScroll: g.paging ? 1 : false,
                maxScroll: 0,
                minScroll: t > j ? j - t : 0,
                snap: g.paging ? j : g.snap ? n || '.mbsc-ms-item' : false,
                elastic: t > j ? n || j : false
            });
            o.refresh(f);
        }
        c.Base.call(this, D, I, true);
        h.navigate = function(a, b) {
            w(r(a), b);
        };
        h.next = function(b) {
            var a = m ? m.next() : y;
            if (a.length) {
                m = a;
                w(m, b);
            }
        };
        h.prev = function(b) {
            var a = m ? m.prev() : y;
            if (a.length) {
                m = a;
                w(m, b);
            }
        };
        h.select = function(b) {
            if (!q) {
                u(a('.mbsc-ms-item-sel', i));
            }
            A(r(b));
        };
        h.deselect = function(a) {
            u(r(a));
        };
        h.enable = function(a) {
            r(a).removeClass('mbsc-btn-d').removeAttr('data-disabled').removeAttr('aria-disabled');
        };
        h.disable = function(a) {
            r(a).addClass('mbsc-btn-d').attr('data-disabled', 'true').attr('aria-disabled', 'true');
        };
        h.refresh = h.position = function(a) {
            i.height('');
            J();
            C(false, a);
            i.height(i.height());
        };
        h.init = function(e) {
            var c;
            h._init(e);
            B = a(g.context == 'body' ? f : g.context);
            if (g.type == 'tabs') {
                g.select = g.select || 'single';
                g.variant = g.variant || 'b';
            } else if (g.type == 'options') {
                g.select = g.select || 'multiple';
                g.variant = g.variant || 'a';
            } else if (g.type == 'menu') {
                g.select = g.select || 'off';
                g.variant = g.variant || 'a';
            }
            if (g.itemWidth && g.snap === d) {
                g.snap = true;
            }
            x = g.variant;
            p = g.select != 'off';
            q = g.select == 'multiple';
            s = ' mbsc-ms-item-sel ' + (g.activeClass || '');
            c = 'mbsc-ms-c' + ' mbsc-ms-' + x + ' mbsc-ms-' + g.display + ' mbsc-' + g.theme + ' ' + (g.baseTheme ? ' mbsc-' + g.baseTheme : '') + ' ' + (g.cssClass || '') + ' ' + (g.wrapperClass || '') + (g.rtl ? ' mbsc-ms-rtl' : ' mbsc-ms-ltr') + (g.itemWidth ? ' mbsc-ms-hasw' : '') + (g.context == 'body' ? '' : ' mbsc-ms-ctx') + (p ? '' : ' mbsc-ms-nosel');
            if (!k) {
                k = a('<div class="' + c + '"><div class="mbsc-ms-sc"></div></div>').insertAfter(i);
                k.find('.mbsc-ms-sc').append(i);
                o = new b.classes.ScrollView(k[0], {
                    axis: 'X',
                    contSize: 0,
                    maxScroll: 0,
                    maxSnapScroll: 1,
                    minScroll: 0,
                    snap: 1,
                    elastic: 1,
                    rtl: g.rtl,
                    mousewheel: g.mousewheel,
                    onBtnTap: function(b) {
                        w(a(b.target), true);
                    },
                    onGestureStart: function(a) {
                        l('onGestureStart', a);
                    },
                    onGestureEnd: function(a) {
                        l('onGestureEnd', a);
                    },
                    onMove: function(a) {
                        l('onMove', a);
                    },
                    onAnimationStart: function(a) {
                        l('onAnimationStart', a);
                    },
                    onAnimationEnd: function(a) {
                        l('onAnimationEnd', a);
                    }
                });
            } else {
                i.height('');
                k.attr('class', c);
            }
            i.css('display', '').addClass('mbsc-ms ' + (g.groupClass || ''));
            J();
            l('onMarkupReady', {
                target: k[0]
            });
            i.height(i.height());
            C();
            k.find('img').on('load', z);
            B.on('orientationchange resize', z);
            l('onInit');
        };
        h.destroy = function() {
            B.off('orientationchange resize', z);
            i.height('').insertAfter(k).find('.mbsc-ms-item').width('');
            k.remove();
            o.destroy();
            h._destroy();
        };
        g = h.settings;
        l = h.trigger;
        h.init(I);
    };
    c.MenuStrip.prototype = {
        _class: 'menustrip',
        _hasDef: true,
        _hasTheme: true,
        _defaults: {
            context: 'body',
            type: 'options',
            display: 'inline',
            layout: 'liquid'
        }
    };
    b.presetShort('menustrip', 'MenuStrip');
}(window, document));
(function() {
    mobiscroll.themes.menustrip['android-holo'] = {};
}());
(function() {
    mobiscroll.themes.menustrip.bootstrap = {
        wrapperClass: 'popover panel panel-default',
        groupClass: 'btn-group',
        activeClass: 'btn-primary',
        disabledClass: 'disabled',
        itemClass: 'btn btn-default'
    };
}());
(function() {
    mobiscroll.themes.menustrip.ios = {};
}());
(function() {
    var a = mobiscroll.$,
        b = a.mobile && a.mobile.version && a.mobile.version.match(/1\.4/);
    mobiscroll.themes.menustrip.jqm = {
        activeClass: 'ui-btn-active',
        disabledClass: 'ui-state-disabled',
        onThemeLoad: function(d) {
            var a = d.settings,
                c = a.jqmSwatch || (b ? 'a' : 'c');
            a.itemClass = 'ui-btn ui-btn-up-' + c;
            a.wrapperClass = 'ui-bar-' + c;
        }
    };
}());
(function() {
    var a = mobiscroll.$;
    mobiscroll.themes.menustrip.material = {
        onInit: function() {
            mobiscroll.themes.material.initRipple(a(this), '.mbsc-ms-item', 'mbsc-btn-d', 'mbsc-btn-nhl');
        },
        onMarkupInit: function() {
            a('.mbsc-ripple', this).remove();
        }
    };
}());
(function() {
    mobiscroll.themes.menustrip.wp = {};
}());
